package framework.util.queryFilter.vo;

import org.apache.commons.lang3.StringUtils;

/**
 * @author 吴宇亮 on 2019/6/10 21:15
 */
public class OrderBy extends AbstactSql {

    public static final String ASC = "asc";
    public static final String DESC = "desc";

    /** 待排序的字段名**/
    private String fieldName;
    private String orderRule;

    public OrderBy(String fieldName, String orderRule) {
        this.fieldName = fieldName;
        this.orderRule = orderRule;
    }

    @Override
    public void generatorSql(Class persistType) throws NoSuchFieldException {
        if(StringUtils.isBlank(fieldName)){
            throw new IllegalArgumentException("待排序的字段不能为空");
        }

        if(ASC.equalsIgnoreCase(orderRule) || DESC.equalsIgnoreCase(orderRule)){
            this.generatorSql = fieldName + " " + orderRule;
        }else{
            throw new IllegalArgumentException("排序规则不合法，排序规则只能为asc或desc");
        }
    }

    public String getFieldName() {
        return fieldName;
    }

    public void setFieldName(String fieldName) {
        this.fieldName = fieldName;
    }

    public String getOrderRule() {
        return orderRule;
    }

    public void setOrderRule(String orderRule) {
        this.orderRule = orderRule;
    }
}
